package models

import (
	"go-web/utils"
)

type AdminParam struct {
	utils.BaseModel
	Key         string `json:"key" gorm:"size:50;comment:参数名称;uniqueIndex"`
	Value       string `json:"value" gorm:"size:255;comment:参数值"`
	Description string `json:"description" gorm:"size:255;comment:参数描述"`
}

// GetParam 获取参数, 可以传指定key，不传默认所有
func GetParam(key ...string) map[string]AdminParam {
	db := utils.GetDB()
	var params []AdminParam
	if len(key) > 0 {
		db = db.Where("`key` in (?)", key)
	}
	db.Find(&params)
	p := make(map[string]AdminParam)
	if len(params) > 0 {
		for _, v := range params {
			p[v.Key] = v
		}
	}
	return p
}
